<?php
/*
 * Created on 2016/11/15
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 require_once('../service/InsertUser.class.php');
 require_once('../service/class.phpmailer.php');
 require_once('../service/class.smtp.php');

 $register = new InsertUser();
 $to = $_POST["forgetEmail"];
 $randValue = mt_rand(100000, 999999);

 $result = $register -> updatePwd(md5($randValue), $to);
 
 //发送邮件
 if($result==0||$result=="0"){
  $mail = new PHPMailer(true); //建立邮件发送类
  $mail->CharSet = "UTF-8";//设置信息的编码类型
  $address = $to;//收件人地址
  $mail->IsSMTP(); // 使用SMTP方式发送
  $mail->Host = "smtp.163.com"; //使用163邮箱服务器
  $mail->SMTPAuth = true; // 启用SMTP验证功能
  $mail->Username = "zyjttianxiangshang@163.com"; //你的163服务器邮箱账号
  $mail->Password = "1986386tyu"; // 163邮箱密码
  $mail->Port = 25;//邮箱服务器端口号
  $mail->From = "zyjttianxiangshang@163.com"; //邮件发送者email地址
  $mail->FromName = "淡炒番茄";//发件人名称
  $mail->AddAddress("$address", ""); //收件人地址，可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
  $mail->IsHTML(true);//是否使用HTML格式
  $mail->Subject = "淡炒番茄密码修改"; //邮件标题
  $mail->Body = "您的密码已修改为随机码：".$randValue."。请用该随机码登录！"; //邮件内容，上面设置HTML，则可以是HTML
  if (!$mail->Send()) {
   echo "0";
   exit;
  }
 }else{
 	echo "1";
 	exit;
 }
 
?>
